import * as cc from "cc";
import { LabelTextId } from "../../../../framework/components/label/LabelTextId";
import { Loger } from "../../../../framework/loger/Loger";
import { ViewLayer } from "../../../../framework/view/ViewConsts";
import ModelFlyIcon, { FlyIconData } from "../../fly_icon/model/ModelFlyIcon";
import ModelGuide from "../../guide/model/ModelGuide";
import VCMainDemo from "../vc/VCMainDemo";
import { ViewBase } from './../../../../framework/view/ViewBase';

const { ccclass, property, menu } = cc._decorator;
@ccclass("ViewMainDemo")
@menu("GameView/ViewMainDemo")
export default class ViewMainDemo extends ViewBase {

    protected static prefabUrl: string = "game/prefab/mvc/demo_main/MainDemo";
    public static className: string = "ViewMainDemo"
    protected vc: VCMainDemo = null;

    @property({ type: cc.Node, tooltip: "主场景" })
    btnMain: cc.Node = null;
    @property({ type: cc.Node, tooltip: "播放引导" })
    btnShowGuide: cc.Node = null;
    @property({ type: cc.Node, tooltip: "引导目标" })
    btnGuideTarget: cc.Node = null;
    @property({ type: LabelTextId, tooltip: "多边形" })
    txtText: LabelTextId = null;

    private guideIdx = 1;
    //生命周期：onInit(加载时只调一次)==>onOpen(每次showui时)==>onShow()==>onStart()==>onHide()==>onClose()
    /**只会在首次加载时调用一次，可以用于获取节点，绑定事件 */
    protected onInit() {
        super.onInit();
        this.setClickListener(this.btnMain, () => {
            this.vc.onClick();
        })

        this.txtText.updateText("main_ui_4", { level: 99 })


        const guidModel = ModelGuide.getInstance() as ModelGuide;
        this.setClickListener(this.btnShowGuide, () => {
            guidModel.tryGuide(this.guideIdx++, this.btnGuideTarget)
        }, this)
        this.setClickListener(this.btnGuideTarget, () => {
            Loger.log("点击引导:", this.guideIdx)
            const flyData: FlyIconData = {
                targetWorldPos: this.btnMain.getComponent(cc.UITransform).convertToWorldSpaceAR(cc.Vec3.ZERO),
                /**飞行图标图片名 优先iconNode */
                iconName: "default_sprite",
                /**飞图标起始位置,如果不传,默认飞行图标起始位置 */
                fromWorldPos: this.btnGuideTarget.getComponent(cc.UITransform).convertToWorldSpaceAR(cc.Vec3.ZERO),
                /**需要创建的数量 */
                flyCount: 10,
                /**飞行图标的缩放比例 */
                iconScaleTo: 1,
                /**初始随机位置范围半径 */
                randomRadius: 300,
                /**飞行图标的根节点层级 优先iconRoot*/
                iconRootLayer: ViewLayer.Layer_Hud_Effect,

            }
            ModelFlyIcon.flyIcon(flyData);
        }, this)
    }

    /**每次打开UI前，onStart前,每次呼出前赋值传参的时候用 */
    protected onOpen() {
        super.onOpen();
    }

    /**开始动画播完 onShow之后*/
    protected onStart() {
        super.onStart();
    }

    /**关闭动画结束后 */
    protected onClose() {
        super.onClose();
    }

    /**update生命周期 */
    protected onUpdate(dt) {
    }


}